home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 1).ISO / Shware / Base Golf / BaseGolf.exe / {app} / BaseGolf.exe / io_funcs.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2002-11-28  |  4.9 KB  |  130 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.1)
  3.  
  4. import os
  5. import pygame
  6. import copy
  7. from pygame.locals import *
  8. from random import randint
  9.  
  10. def load_image_init():
  11.     global image_dict
  12.     image_dict = { }
  13.  
  14.  
  15. def load_image(name, colorkey = None, cache = 1):
  16.     if not image_dict.has_key(name) or not cache:
  17.         
  18.         try:
  19.             if colorkey is not None:
  20.                 image = pygame.image.load(name)
  21.                 image.convert()
  22.                 if colorkey is not None and colorkey != 0:
  23.                     if colorkey is -1:
  24.                         colorkey = image.get_at((0, 0))
  25.                     
  26.                     colorkey_used = image.set_colorkey(colorkey, RLEACCEL)
  27.                 
  28.             else:
  29.                 image = pygame.image.load(name)
  30.                 image = image.convert_alpha()
  31.         except pygame.error:
  32.             message = None
  33.             return (None, None)
  34.  
  35.         image_dict[name] = image
  36.         return (image, image.get_rect())
  37.     else:
  38.         return (image_dict[name], image_dict[name].get_rect())
  39.  
  40.  
  41. def load_dict(filename, dict, compressed = 0):
  42.     if not os.path.exists(filename):
  43.         return None
  44.     
  45.     if compressed == 0:
  46.         file = open(filename, 'rb')
  47.     else:
  48.         file = gzip.open(filename, 'rb')
  49.     lines = file.readlines()
  50.     for line in lines:
  51.         line = line.rstrip()
  52.         (key, value) = line.split('=', 1)
  53.         
  54.         try:
  55.             int(value)
  56.         except ValueError:
  57.             0
  58.             0
  59.             lines
  60.         except:
  61.             0
  62.  
  63.         value = int(value)
  64.         dict[key] = copy.deepcopy(value)
  65.     
  66.     file.close()
  67.  
  68.  
  69. def load_file(filename):
  70.     if not os.path.exists(filename):
  71.         return None
  72.     
  73.     file = open(filename, 'rb')
  74.     data = file.read()
  75.     return data
  76.  
  77.  
  78. def save_file(filename, data):
  79.     file = open(filename, 'wb')
  80.     file.write(data)
  81.  
  82.  
  83. def save_dict(filename, dict, compressed = 0):
  84.     if compressed == 0:
  85.         file = open(filename, 'wb')
  86.     else:
  87.         file = gzip.open(filename, 'wb')
  88.     for item in dict.items():
  89.         file.write('%s=%s\n' % (str(item[0]), str(item[1])))
  90.     
  91.     file.close()
  92.  
  93.  
  94. def draw_text_init(screenRect, screen, gameScreen):
  95.     global font_dict
  96.     font_dict = { }
  97.  
  98.  
  99. def draw_text(text, size, color, pos, surface, align_flag = 0, draw_flag = 0, draw_flag_data = 0, width = -1, effect = 0, effectPer = 1.0):
  100.     offset = [
  101.         0,
  102.         0]
  103.     if not (pygame.font):
  104.         return offset
  105.     
  106.     if text == '':
  107.         return offset
  108.     
  109.     if font_dict.has_key(size) == 0:
  110.         font_dict[size] = pygame.font.Font('data/tahoma.ttf', size)
  111.     
  112.     if text.find('\n', 0) != -1:
  113.         lines = text.split('\n')
  114.     else:
  115.         lines = text.split('\\n')
  116.     count = 0
  117.     if effect != 0:
  118.         if effect == 1:
  119.             if effectPer > 0.5:
  120.                 effectPer = 0.5 - effectPer - 0.5
  121.             
  122.             scale = 1.0 + 0.17 * effectPer
  123.         
  124.     
  125.     for line in lines:
  126.         count += 1
  127.     
  128.     return (offset, count)
  129.  
  130.